Docker : Use Dockerfile#2
2016/06/17 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|
[1] | For example, Create a Dockerfile to install Apache2 and add index.html, and also start Apache2 with 80 port. |
root@dlp:~#
vi Dockerfile # create new FROM ubuntu MAINTAINER ServerWorld <admin@srv.world> RUN apt-get update RUN apt-get -y install apache2 RUN echo 'Hello DockerFile' > /var/www/html/index.html RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh RUN echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh RUN echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh RUN echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh RUN chmod 755 /root/run_apache.sh EXPOSE 80 CMD /root/run_apache.sh # build image ⇒ docker build -t [image name]:[tag] . root@dlp:~# docker build -t apache_httpd:latest . ..... ..... ..... Step 10 : RUN chmod 755 /root/run_apache.sh ---> Using cache ---> 08e27423dcde Step 11 : EXPOSE 80 ---> Using cache ---> f1b699db5891 Step 12 : CMD /root/run_apache.sh ---> Using cache ---> bb537256b647 Successfully built bb537256b647root@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE apache_httpd latest bb537256b647 8 minutes ago 258.7 MB my_image/ubuntu_httpd latest 65d1b6d04b37 2 days ago 258.7 MB my_image/ubuntu_sshd latest dff14a9cd0ff 2 days ago 214.5 MB ubuntu latest 2fa927b5cdd3 3 weeks ago 122 MB # run Container on background root@dlp:~# docker run -d -p 80:80 apache_httpd e62458c61bab8d3ad4d1fea256185e122951db666cbbbf51e6ae98dcdc2e2f22 root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e62458c61bab apache_httpd "/bin/sh -c /root/run" 11 seconds ago Up 11 seconds 0.0.0.0:80->80/tcp agitated_poitrasroot@dlp:~# curl http://localhost/ Hello DockerFile |